﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestWizardsForms
{
    public class IconComparer : IComparer
    {
        private const int columnIndex = 1;

        public int Compare(object x, object y)
        {
            ListViewItem listX = (ListViewItem)x;
            ListViewItem listY = (ListViewItem)y;

            // Convert column text to numbers before comparing.
            // If the conversion fails, just use the value 0.
            string listXVal, listYVal;
            try
            {
                listXVal = listX.SubItems[columnIndex].Text;
            }
            catch
            {
                listXVal = "";
            }

            try
            {
                listYVal = listY.SubItems[columnIndex].Text;
            }
            catch
            {
                listYVal = "";
            }

            return (String.Compare(listXVal, listYVal));
        }
    }
}
